package com.spring.sperapc.web.service.impl;

import java.io.File;
import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.spring.sperapc.web.dao.UserDetailMapper;
import com.spring.sperapc.web.model.UserDetail;
import com.spring.sperapc.web.service.UserDetailService;

/**
 * Created by wojunyu on 2015/8/12.
 */
@Service
public class UserDetailServiceImpl implements UserDetailService {
    @Resource
    private UserDetailMapper userDetailMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return userDetailMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertSelective(UserDetail record) {
        return userDetailMapper.insertSelective(record);
    }

    @Override
    public UserDetail selectByPrimaryKey(String id) {
        return userDetailMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(UserDetail record) {
        return userDetailMapper.updateByPrimaryKeySelective(record);
    }

	@Override
	public int updateWxPoint(String c_user_id,String wx_point) {
		// TODO Auto-generated method stub
		HashMap hm=new HashMap();
		hm.put("c_user_id", c_user_id);
		hm.put("wx_point", wx_point);
		return userDetailMapper.updateWxPoint(hm);
	}

	@Override
	public int updateUserImageSrc(String c_user_id, String image_src,String root) {
		// TODO Auto-generated method stub
		
		String image_src_org=userDetailMapper.updateUserImageSrcGetOrgan(c_user_id);
		
		
		System.out.println("得到删除的图片路径"+root+image_src_org);
		
		if(image_src_org!=null){
			File f=new File(root+image_src_org);
			if(f.exists()){
				f.delete();
				System.out.println(image_src_org+"已删除");
			}
			
		}
		
		HashMap hm=new HashMap();
		hm.put("c_user_id", c_user_id);
		hm.put("image_src", image_src);
		System.out.println(hm.toString());
		
		int effect=userDetailMapper.updateUserImageSrc(hm);
		System.out.println(effect+"effect");
		
		
		
		return effect;
	}
}
